package com.zwh.shardingjdbc.config;


import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

//import com.xxl.job.common.persistence.interceptor.PaginationInterceptor;

/**
 * @Author zwh
 * @Date 2019/12/27 16:11
 **/

@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
//annotationClass= org.apache.ibatis.annotations.Mapper.class
@MapperScan(basePackages ="com.zwh.shardingjdbc.modules", annotationClass = Mapper.class) //设置数据库dao接口所在包位置，默认设置为@mapper注解标记
public class MyBatisPlusConfig {
/*org.springframework.jdbc.datasource.DataSourceTransactionManager*/
    /*@Qualifier("dataSource")
    @Autowired
    DataSource dataSource;*/

    /*@Bean("txManager")
    public DataSourceTransactionManager txManager() {
        return new DataSourceTransactionManager(dataSource);
    }*/

    /**
     * mybatis-plus分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
        // paginationInterceptor.setOverflow(false);
        // 设置最大单页限制数量，默认 500 条，-1 不受限制
         paginationInterceptor.setLimit(-1);
        return paginationInterceptor;
    }

    /**
     * SQL执行效率插件 3.2以上被移除
     */
    /*@Bean
    @Profile({"dev","test"})// 设置 dev test 环境开启
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }*/

    // mybatis-plus乐观锁插件,需要搭配@Version注解
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }

    /*@Bean
    public MybatisPlusPropertiesCustomizer plusPropertiesCustomizer() {
         return new MybatisPlusPropertiesCustomizer() {
             @Override public void customize(MybatisPlusProperties properties) {
                 properties.getGlobalConfig();
             }
         };
//        return plusProperties-> plusProperties.getGlobalConfig()
    }*/

    /**
     * 设置id生成器
     * @return
     */
    /*@Bean
    public IdentifierGenerator idGenerator() {
        return new CustomIdGenerator();
    }*/

    /**
     * 自定义sql注入
     */
    /*@Bean
    public MySqlInjector sqlInjector() {
        return new MySqlInjector();
    }*/
}
